//
//  ZCRankingListModelContent.m
//
//  Created by   on 16/2/26
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "ZCRankingListModelContent.h"


NSString *const kZCRankingListModelContentSlogan = @"slogan";
NSString *const kZCRankingListModelContentCtime = @"ctime";
NSString *const kZCRankingListModelContentId = @"id";
NSString *const kZCRankingListModelContentMid = @"mid";
NSString *const kZCRankingListModelContentVoteNum = @"vote_num";
NSString *const kZCRankingListModelContentThumb = @"thumb";
NSString *const kZCRankingListModelContentRank = @"rank";
NSString *const kZCRankingListModelContentVotename = @"vote_name";
NSString *const kZCRankingListModelContentQrcodelurl = @"qrcode_url";


@interface ZCRankingListModelContent ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ZCRankingListModelContent

@synthesize slogan = _slogan;
@synthesize ctime = _ctime;
@synthesize contentIdentifier = _contentIdentifier;
@synthesize mid = _mid;
@synthesize voteNum = _voteNum;
@synthesize thumb = _thumb;
@synthesize rank = _rank;
@synthesize vote_name = _vote_name;
@synthesize qrcode_url = _qrcode_url;

+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.slogan = [self objectOrNilForKey:kZCRankingListModelContentSlogan fromDictionary:dict];
            self.ctime = [self objectOrNilForKey:kZCRankingListModelContentCtime fromDictionary:dict];
            self.contentIdentifier = [self objectOrNilForKey:kZCRankingListModelContentId fromDictionary:dict];
            self.mid = [self objectOrNilForKey:kZCRankingListModelContentMid fromDictionary:dict];
            self.voteNum = [self objectOrNilForKey:kZCRankingListModelContentVoteNum fromDictionary:dict];
            self.thumb = [self objectOrNilForKey:kZCRankingListModelContentThumb fromDictionary:dict];
            self.rank = [self objectOrNilForKey:kZCRankingListModelContentRank fromDictionary:dict];
        self.vote_name = [self objectOrNilForKey:kZCRankingListModelContentVotename fromDictionary:dict];
        self.qrcode_url = [self objectOrNilForKey:kZCRankingListModelContentQrcodelurl fromDictionary:dict];
    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.slogan forKey:kZCRankingListModelContentSlogan];
    [mutableDict setValue:self.ctime forKey:kZCRankingListModelContentCtime];
    [mutableDict setValue:self.contentIdentifier forKey:kZCRankingListModelContentId];
    [mutableDict setValue:self.mid forKey:kZCRankingListModelContentMid];
    [mutableDict setValue:self.voteNum forKey:kZCRankingListModelContentVoteNum];
    [mutableDict setValue:self.thumb forKey:kZCRankingListModelContentThumb];
    [mutableDict setValue:self.rank forKey:kZCRankingListModelContentRank];
    [mutableDict setValue:self.vote_name forKey:kZCRankingListModelContentVotename];
    [mutableDict setValue:self.qrcode_url
                   forKey:kZCRankingListModelContentQrcodelurl];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.slogan = [aDecoder decodeObjectForKey:kZCRankingListModelContentSlogan];
    self.ctime = [aDecoder decodeObjectForKey:kZCRankingListModelContentCtime];
    self.contentIdentifier = [aDecoder decodeObjectForKey:kZCRankingListModelContentId];
    self.mid = [aDecoder decodeObjectForKey:kZCRankingListModelContentMid];
    self.voteNum = [aDecoder decodeObjectForKey:kZCRankingListModelContentVoteNum];
    self.thumb = [aDecoder decodeObjectForKey:kZCRankingListModelContentThumb];
    self.rank = [aDecoder decodeObjectForKey:kZCRankingListModelContentRank];
    self.vote_name = [aDecoder decodeObjectForKey:kZCRankingListModelContentVotename];
    self.qrcode_url = [aDecoder decodeObjectForKey:kZCRankingListModelContentQrcodelurl];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_slogan forKey:kZCRankingListModelContentSlogan];
    [aCoder encodeObject:_ctime forKey:kZCRankingListModelContentCtime];
    [aCoder encodeObject:_contentIdentifier forKey:kZCRankingListModelContentId];
    [aCoder encodeObject:_mid forKey:kZCRankingListModelContentMid];
    [aCoder encodeObject:_voteNum forKey:kZCRankingListModelContentVoteNum];
    [aCoder encodeObject:_thumb forKey:kZCRankingListModelContentThumb];
    [aCoder encodeObject:_rank forKey:kZCRankingListModelContentRank];
    [aCoder encodeObject:_vote_name forKey:kZCRankingListModelContentVotename];
    [aCoder encodeObject:_qrcode_url forKey:kZCRankingListModelContentQrcodelurl];
}

- (id)copyWithZone:(NSZone *)zone
{
    ZCRankingListModelContent *copy = [[ZCRankingListModelContent alloc] init];
    
    if (copy) {

        copy.slogan = [self.slogan copyWithZone:zone];
        copy.ctime = [self.ctime copyWithZone:zone];
        copy.contentIdentifier = [self.contentIdentifier copyWithZone:zone];
        copy.mid = [self.mid copyWithZone:zone];
        copy.voteNum = [self.voteNum copyWithZone:zone];
        copy.thumb = [self.thumb copyWithZone:zone];
        copy.rank = [self.rank copyWithZone:zone];
        copy.vote_name = [self.vote_name copyWithZone:zone];
        copy.qrcode_url = [self.qrcode_url copyWithZone:zone];
    }
    
    return copy;
}


@end
